﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sharp.DataTransferObject;
using Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates;
using Sharp.Infrastructure;
using Sharp.Infrastructure.Search;

namespace Sharp.Application.Platform
{
    public partial class UserServiceImpl
    {
        /// <summary>
        /// 保存用户日志
        /// </summary>
        /// <param name="log"></param>
        public void SaveLog(string log)
        {
            var userLog = log.FromJson<UserLog>();
            userLog.Eventtime = DateTime.Now;

            _userLogRepository.Add(userLog);

            Context.Commit();
        }


        public UserLogDTO GetUserLogInfo(Guid id)
        {
            var model = _userLogRepository.Get(id);

            return model.To<UserLogDTO>();
        }

        public Result DeleteUserLogs(Guid[] ids)
        {
            Result res = new Result();
            if (ids.IsEmpty())
            {
                res.Err = "id不能为空";
                return res;
            }
            _userLogRepository.Remove(ids);
            Context.Commit();

            return res;
        }

        public PagedResult<UserLogDTO> GetUserLogPaged(PagingFeature pf)
        {
            var paged = _userLogRepository.Pagging(pf);

            var output = paged.To<UserLog, UserLogDTO>();


            return output;
        }
    }
}